package com.ztrue.framework.context;

import com.ztrue.framework.Config;
import com.ztrue.common.properties.Prop;
import com.ztrue.common.properties.Proper;
import com.ztrue.common.utilities.Assert;

/**
 * 应用程序上下文提供者
 *
 * @author zhangw
 * @date 2016/11/17 20:44
 * @version: 1.0
 */
public abstract class ApplicationContextProvider {

    /**
     * 应用程序上下文
     */
    public final static AbstractApplicationContext APPLICATIONCONTEXT;

    static {
        Prop prop = Proper.use(Config.CONFIG_PATH);
        Assert.notNull(prop, "无法获取默认配置文件");
        String runSurroundings = prop.get("ztrue.run.surroundings", "CLASSPATH").toUpperCase();
        switch (runSurroundings) {
            case "CLASSPATH":
                APPLICATIONCONTEXT = new ClassPathApplicationContext();
                break;
            default:
                APPLICATIONCONTEXT = null;
        }
        Assert.notNull(APPLICATIONCONTEXT, "无法创建应用程序上下文");
    }

    /**
     * 获取领域事件内部处理器提供者
     *
     * @return
     */
    public static IAggregateRootInternalHandlerProvider getAggregateRootInternalHandlerProvider() {
        return APPLICATIONCONTEXT.getAggregateRootInternalHandlerProvider();
    }
}